<include file="public@storage"/>
<link rel="stylesheet" href="__STATIC__/storage/js/bom/bom.css"/>
</head>
<body>

<div class="container body-content" style="width: 100%;margin-top:20px;">
    <div class="panel panel-primary" style="margin-bottom: 0.5rem">
        <div class="panel-heading">齐套查询<span
                id="condition"></span></div>
        <div class="panel-body">
            <div class="row">
                <div class="col-sm-12">
                    <div id="toolbar" class="btn-group">
                        <div style="height:55px;width:fit-content;width:-moz-fit-content;float: left">
                            <input type="hidden" id="hidden" value="1">
                            <input type="text" name="order" id="order" class="mui-btn mui-btn--raised "
                                   title="注：导入委外订单请输入“单号+行号”" placeholder="委外单请输入“单号+行号”">
                            <button type="button" class="mui-btn mui-btn--raised mui-btn--primary" id="ask">K3导入
                            </button>
                        </div>
                    </div>
                    <table id="table"></table>
                </div>
            </div>
        </div>
    </div>
</div>
</body>
<script src="__STATIC__/storage/js/bom/add.js"></script>
<script>

    $(function () {
        init();
    });

    function init() {
        var url = "{:url('Bom/getBom')}?hidden=1";
        var columns = [
            {
                title: '序号',
                width: 50,
                align: "center",
                valign: 'middle',
                formatter: function (value, row, index) {
                    return index + 1;
                }
            },
            {title: 'uuid', field: 'uuid', visible: false, searchable: false},
            {
                title: '单号',
                field: 'order_id',
                align: "center",
                valign: 'middle',
                filter: {
                    type: 'input'
                }
            },
            {
                title: '行号',
                field: 'fentryid',
                align: "center",
                valign: 'middle',
                filter: {
                    type: 'input'
                }
            },
            {
                title: '委外厂商',
                field: 'company_name',
                align: "center",
                valign: 'middle',
                filter: {
                    type: 'input'
                }
            },
            {
                title: '时间',
                field: 'time',
                align: "center",
                valign: 'middle',
                filter: {
                    type: 'input'
                }
            },
            {
                title: '状态',
                field: 'status',
                width: 150,
                align: "center",
                valign: 'middle',
                filter: {
                    type: 'input'
                },
                formatter: function (value, row, index) {
                    var html = '';
                    console.log(value);
                    if (value == 0) {
                        html += '<label class="undo">未出库</label>';
                    } else if (value == 1) {
                        html += '<label class="unfinished">已完成</label>';
                    } else if (value == 2) {
                        html += '<label class="owe">欠料</label>';
                    } else {
                        html += '<label class="finished">未完成</label>';
                    }
                    return html;
                }
            },
            {
                title: '操作',
                width: 300,
                align: "center",
                valign: 'middle',
                formatter: function (value, row,index) {
                    return '<a onclick="deleteBom(this)" href="javascript:void(0);" data-uuid="'+row.uuid+'"> 删除</a>';
                }
            }
        ];
        initTable(url, columns, 'server', InitSubTable);
        setColumn();
    }

    InitSubTable = function (index, row, $detail) {
        var tableId = "cur_table_"+index;
        $detail.html('<table id="'+ tableId+ '"></table>').find('table');
        var bomUuid = row.uuid;
        var fentryid = row.fentryid;
        var orderId = row.order_id;
        var url = "{:url('Bom/getBomDetail')}?bomUuid=" + bomUuid + '&orderId=' + orderId + '&fentryid=' + fentryid ;
        console.log(url);
        var column = [
            {
                title: '序号',
                width: 50,
                align: "center",
                valign: 'middle',
                searchable: false,
                formatter: function (value, row, index) {
                    return index + 1;
                }
            },
            {
                title: 'uuid',
                field: 'uuid',
                visible: false,
                searchable: false
            },
            {
                title: '物料号',
                field: 'sub_materiel_id',
                align: "center"
            },
            {
                title: '物料名称',
                field: 'sub_materiel_name',
                align: "center"
            },
            {
                title: '投料数量',
                field: 'count',
                align: "center"
            },
            {
                title: '账上库存',
                field: 's_count',
                align: "center"
            },
            {
                title: '架上库存',
                field: 'r_count',
                align: "center"
            },
            {
                title: '已发数量',
                field: 'send',
                align: "center"
            },
            {
                title: '投料减已发',
                field: 'diff',
                align: "center",
                valign: 'middle',
                formatter: function (value, row, index) {
                    if (value < 0) {
                        return '多发' + (0 - value);
                    } else if (value > 0) {
                        return '未发' + value;
                    } else {
                        return 0;
                    }
                }
            },
            {
                title: '齐套',
                field: 'kitting',
                align: 'center',
                formatter: function (value, row, index) {
                    if (value == 1) {
                        return '<label class="finished">齐套</label>';
                    } else {
                        return '<label class="undo">未齐套</label>';
                    }
                }
            }
        ];
        initSubTable(tableId,url, column, 'client', true);
    };

    deleteBom = function (that) {
        var uuid = $(that).data('uuid');
        var row = $('#table').bootstrapTable('getRowByUniqueId', uuid);
        var fen = row.fentryid ? ('+' + row.fentryid) : '';
        orderId = row.order_id + fen;
        var tip = '是否删除' + orderId + '订单？';
        var url = "{:url('Other/delete')}";
        var data = {uuid: uuid};
        reviseTable(tip, url, data);
    };

    calculate = function (row) {
        var uuid = row.uuid;
        $.ajax({
            url: "/storage/Bom/checkKitting",
            dataType: "json",
            type: 'POST',
            data: {uuid: uuid},
            beforeSend: function () {
                $('.loading').show();
            }, complete: function () {
                $('.loading').hide();
            }, success: function (res) {
                console.log(res);
                if (res.success === true) {
                    layer.msg(res.message);
                    //将开头写到前面
                    var str = /\w[A-z]+/.exec(order)[0];
                    $('#order').val(str);
                } else if (res.success === false) {
                    layer.msg(res.message);
                }
            }, error: function () {
                layer.msg('网络错误');
            }
        })
    };
</script>
</html>